/**
 * 
 */
package indexer;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

/**
 * @author Pascal de Vink
 * @version 0.2
 */
public class Logger {
	
	File logfile;
	FileOutputStream fos;
	
	public Logger(File log)
	{
		this.logfile = log;
		
		if (!this.logfile.exists())
		{
			try {
				this.logfile.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
				return;
			}
		}
		
		if (!this.logfile.canWrite())
		{
			this.logfile.setWritable(true);
		}
		
		if (this.logfile.canWrite())
		{
			try {
				this.fos = new FileOutputStream(this.logfile);
			} catch (FileNotFoundException e) {
				System.out.println("Logger");
				e.printStackTrace();
				return;
			}
		}
	}	
	
	public void writeLine(String line)
	{
		new PrintStream(this.fos).println(line + "\n");
	}
	
	public void writeString(String text)
	{
		new PrintStream(this.fos).print(text);
	}
	
	public void closeLogger()
	{
		try {
			this.fos.close();
		} catch (IOException e) {
			System.out.println("Logger");
			e.printStackTrace();
			return;
		}
	}
}
